/**
 * Created by wzq on 15-3-28.
 */

var mongodb = require('./mongodb.js');
var Schema = mongodb.Schema;

// create a schema
var employeeSchema = new Schema({
  weixin_userid: {
    type: String,
    required: true,
    index: true,
    unique: true
  },
  name: String,
  department: Array,
  position: String,
  mobile: String,
  email: String,
  avatar: String,
  status: String,
  extattr: Schema.Types.Mixed,
  //
  created_at: Date,
  updated_at: {
    type: Date,
    default: Date.now
  }
});

employeeSchema.pre('save', function(next) {
  var currentDate = new Date();
  if (!this.created_at) {
    this.created_at = currentDate;
  }
  next();
});

var Employee = mongodb.model('Employee', employeeSchema);

module.exports = Employee;
